package java;

public class Question24 {
    public static void main(String[] args) {

    }
    public static ListNode swapPairs(ListNode head) {
        if (head == null){
            return null;
        }
        ListNode root = head;
        if (head.next == null){
            return root;
        }
        ListNode current = head;
        ListNode before = null;
        while (current != null && current.next != null){
            ListNode temp = current.next.next;
            if (before != null){
                before.next = current.next;
            }else {
                root = current.next;
            }
            current.next.next = current;
            current.next = temp;
            before = current;
            current = current.next;
        }
        return root;
    }
}
